home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 25
/
AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso
/
Updates
/
HD-Installer
/
jst_dev
/
sources
/
OSEmu
/
dos.s
< prev
next >
Wrap
Text File
|
2000-04-12
|
19KB
|
982 lines
;APS00000000000000000000000000000000000000000000000000000000000000000000000000000000
* $Id: dos.s 1.1 1999/02/03 04:09:58 jotd Exp $
**************************************************************************
* DOS-LIBRARY *
**************************************************************************
**************************************************************************
* INITIALIZING *
**************************************************************************
DOSINIT move.l _dosbase,d0
beq .init
rts
.init move.l #1050,d0 ;(reserved function)
move.l #$46,d1
lea _dosname,a0
bsr _InitLibrary
move.l d0,a0
move.l d0,_dosbase
patch _LVOLoadSeg(a0),DOSLOADSEG(pc)
patch _LVOUnLoadSeg(a0),DOSUNLOADSEG(pc)
patch _LVOOpen(a0),DOSOPEN(PC)
patch _LVOClose(a0),DOSCLOSE(PC)
patch _LVORead(a0),DOSLOAD(PC)
patch _LVOWrite(a0),DOSSAVE(PC)
patch _LVOSeek(a0),DOSSEEK(PC)
patch _LVOLock(A0),DOSLOCK(PC)
patch _LVOInput(A0),MYRTZ(PC)
patch _LVOOutput(A0),MYRTZ(PC)
patch _LVODeviceProc(A0),MYRTZ(PC)
patch _LVOExamine(A0),_EXAMINE(PC)
patch _LVOExNext(A0),_EXNEXT(PC) ; added by JOTD
patch _LVOExamineFH(A0),_EXAMINEFH(PC) ; added by JOTD
patch _LVOIoErr(A0),_IOERR(PC) ; added by JOTD
patch _LVOUnLock(A0),_DOSUNLOCK(PC)
patch _LVOInfo(A0),DOSINFO(PC)
patch _LVODupLock(A0),_DUPLOCK(PC)
patch _LVOWaitForChar(A0),MYRTZ(PC)
patch _LVOCurrentDir(A0),MYRTZ(PC)
patch _LVODelay(A0),DOSDELAY(PC) ; added by JOTD
patch _LVOAssignPath(a0),ASSIGNPATH(PC)
patch _LVOAssignLock(a0),ASSIGNLOCK(PC)
patch _LVORunCommand(a0),RUNCOMMAND(PC) ; added by JOTD
patch _LVOGetArgStr(a0),GETARGSTR(PC) ; added by JOTD
rts
**************************************************************************
* PROGRAM EXECUTION *
**************************************************************************
;<D1:SEGLIST
;<D2:STACKSIZE
;<D3:ARGPTR
;<D4:ARGSIZE
;RUNCOMMAND will ignore STACKSIZE: it will use the current stack
RUNCOMMAND:
move.l D3,args_ptr
;; move.l D4,D0
LSL.L #2,D1
MOVE.L D1,A1
ADDQ.L #4,A1
jmp (A1) ; executes the program
GETARGSTR:
move.l args_ptr(pc),D0
rts
args_ptr:
dc.l 0
_IOERR:
move.l last_io_error(pc),D0
move.l #ERROR_DIR_NOT_FOUND,last_io_error
rts
last_io_error:
dc.l 0
; ******************************************
; 2 special macros added by JOTD for LoadSeg:
; calls EnterDebugger when a condition is reached:
BREAK_ON_COND:MACRO
cmp.l \1,\2
bne.b .ok\@
bsr EnterDebugger
nop
nop
.ok\@
ENDM
; branch with call to EnterDebugger when true
; (to trap error code source)
; uncomment to activate
;BRANCH_COND:MACRO
; \1 .sk\@
; bra.b .end\@
;.sk\@
; bsr EnterDebugger
; bra \2
;.end\@
; ENDM
BRANCH_COND:MACRO
\1 \2 ; this is the non-debug configuration
ENDM
;>D1:FILENAME
;<D0:FIRST SEGMENT
;INTERNAL: D7-TOTAL # OF SEGMENTS
; D6-FILEHANDLE
; D5-SEGMENTBASE
; A4-8 BYTES SPACE ON STACK FOR HUNKHEADERS
;LIMITATIONS: ONLY FOLLOWING HUNKS ALLOWED: HUNK_CODE, HUNK_DATA, HUNK_BSS,
; HUNK_END, HUNK_RELOC32, HUNK_HEADER, HUNK_DEBUG, HUNK_SYMBOL
; CONTACT IF YOU HAVE AN EXE WITH OTHER HUNKS, IM SIMPLY MISSING
; THE EXAMPLES TO IMPLEMENT THEM
DOSLOADSEG:
MOVEM.L D2-D7/A2-A4,-(A7)
SUBQ.L #8,A7
MOVE.L A7,A4
MOVE.L #MODE_OLDFILE,D2
BSR.W DOSOPEN
TST.L D0
BRANCH_COND BEQ.W,.ERR
MOVE.L D0,D6
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR2
CMP.L #$3F3,(A4) ;FIRST LW=HUNK_HEADER?
BRANCH_COND BNE.W,.ERR2
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR2
TST.L (A4) ;NO NAME PLEASE
BRANCH_COND BNE.W,.ERR2
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR2
MOVE.L (A4),D7 ;TOTAL # OF HUNKS
SUBQ.L #1,D7
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #8,D3
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR2
TST.L (A4) ;FIRST HUNK HAS TO BE 0
BRANCH_COND BNE.W,.ERR2
CMP.L 4(A4),D7 ;LAST HUNK HAS TO BE HUNK_COUNT
BRANCH_COND BNE.W,.ERR2
MOVEQ.L #0,D4 ;ALLOC MEM FOR ALL SEGMENTS
MOVEQ.L #0,D5
.1
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3 ;GET SIZE AND MEMFLAGS OF HUNK
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
MOVE.L (A4),D0
; added by JOTD: check memtype requirement
bsr .getmemflag ; >D1: MEMF_xxx
; compute mem size
LSL.L #2,D0
ADDQ.L #8,D0
MOVE.L D0,D2 ;ALLOC MEM IN SIZE
ADDQ.L #7,D0
AND.L #$FFFFFFF8,D0
BSR.W ALLOCM
TST.L D0
BRANCH_COND BEQ.W,.ERR3
MOVE.L D0,A3
MOVE.L D2,(A3)
CLR.L 4(A3)
TST.L D4
BNE.S .2
MOVE.L D0,D5 ;D5-POINTER TO 1ST SEGMENT
BRA.S .3
.2
MOVE.L D5,A3 ;POINTER TO 1ST SEGMENT
.5 TST.L 4(A3)
BEQ.S .4
MOVE.L 4(A3),D2 ;NEXT SEGMENT
LSL.L #2,D2
SUBQ.L #4,D2
MOVE.L D2,A3
BRA.S .5
.4 ADDQ.L #4,D0
LSR.L #2,D0
MOVE.L D0,4(A3)
.3 ADDQ.L #1,D4
CMP.L D7,D4
BLS.S .1
;HEADER COMPLETE, MEM ALLOCATED
;NOW PROCESSING THE HUNK_CODE, HUNK_DATA AND HUNK_BSS
MOVEQ.L #0,D4
.HN MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3 ;GET TYPE OF HUNK
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3 ;END OF FILE ENCOUNTERED
.MAINHUNKS:
AND.L #$3FFFFFFF,(A4)
CMP.L #$3E9,(A4) ;HUNK_CODE?
BEQ.W .HCD
CMP.L #$3F1,(A4) ;HUNK_DEBUG?
BEQ.S .HDEBUG1
CMP.L #$3EA,(A4) ;HUNK_DATA?
BEQ.S .HCD
CMP.L #$3EB,(A4) ;HUNK_BSS?
BEQ.S .HBSS
BRANCH_COND BRA.W,.ERR3
; debug hunk support, added by JOTD
.HDEBUG1:
bsr.s .HDEBUG
BRA.W .HN
.HDEBUG2
bsr.s .HDEBUG
bra .INNERHUNK
.HDEBUG:
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3
BSR.W DOSLOAD ;GET HUNK LENGTH
MOVE.L (A4),D0
add.l D0,D0
add.l D0,D0
MOVE.L D6,D1
MOVE.L D0,D2
MOVE.L #OFFSET_CURRENT,D3
BSR.W DOSSEEK ;SKIP DEBUG DATA
CMP.L #-1,D0
BRANCH_COND BEQ.W,.ERR3
RTS
.HBSS
MOVE.L D6,D1 ;BSS-HUNK
MOVE.L A4,D2
MOVEQ.L #4,D3 ;IGNORE SIZE OF HUNK
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
BRA.S .INNERHUNK
.HCD
MOVE.L D6,D1 ;CODE- AND DATA-HUNK
MOVE.L A4,D2
MOVEQ.L #4,D3 ;GET SIZE OF HUNK
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
MOVE.L (A4),D3 ;LEN OF HUNK
beq .INNERHUNK ; added by JOTD, hunk code can be of 0 length
LSL.L #2,D3
MOVE.L D4,D1 ;ACTUAL HUNK
MOVE.L D5,A3 ;START OF 1ST SEGMENT
BRA.S .HCD1
.HCD2 MOVE.L 4(A3),D2
LSL.L #2,D2
SUBQ.L #4,D2
MOVE.L D2,A3
.HCD1 DBF D1,.HCD2
MOVE.L A3,D2
ADDQ.L #8,D2
MOVE.L D6,D1
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
.INNERHUNK:
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3 ;GET TYPE OF HUNK
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
CMP.L #$3EC,(A4) ;HUNK_RELOC32?
BEQ.S .HRELOCT
CMP.L #$3F2,(A4) ;HUNK_END?
BEQ.W .HENDT
CMP.L #$3F0,(A4) ;HUNK_SYMBOL?
BEQ.W .HSYMBOLT
CMP.L #$3F1,(A4) ;HUNK_DEBUG?
BEQ.W .HDEBUG2
BRANCH_COND BRA.W,.ERR3
.HRELOCT
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3 ;GET COUNT OF LW-RELOCS
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
TST.L (A4) ;END OF RELOCATION?
BEQ.S .INNERHUNK
MOVE.L D6,D1
MOVE.L A4,D2
ADDQ.L #4,D2
MOVEQ.L #4,D3 ;GET CORRESPONDING HUNK TO RELOCATE TO
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR3
MOVE.L (A4),D0
bsr .getmemflag
LSL.L #2,D0 ;ALLOC MEM OF SIZE OF RELOCTABLE
ADDQ.L #7,D0
AND.L #$FFFFFFF8,D0
BSR.W ALLOCM
TST.L D0
BRANCH_COND BEQ.W,.ERR4
MOVE.L D0,A2
MOVE.L D6,D1
MOVE.L A2,D2
MOVE.L (A4),D3 ;GET CORRESPONDING RELOCS TO RELOCATE
LSL.L #2,D3
BSR.W DOSLOAD
TST.L D0
BRANCH_COND BEQ.W,.ERR4
MOVE.L (A4),D3 ;# OF RELOCS
MOVE.L 4(A4),D2 ;WHICH HUNK TO RELOCATE TO?
MOVE.L D5,A0
BRA.S .HRELOCT3
.HRELOCT4
MOVE.L 4(A0),D0
LSL.L #2,D0
SUBQ.L #4,D0
MOVE.L D0,A0
.HRELOCT3
DBF D2,.HRELOCT4
ADDQ.L #8,A0
MOVE.L A0,D0 ;GOT THE HUNK TO RELOCATE TO
LEA.L 8(A3),A1 ;THIS HUNK WILL BE RELOCATED
MOVE.L A2,A0 ;HERE ARE THE RELOCS
BRA.S .HRELOCT5
.HRELOCT6
MOVE.L (A0)+,D1
ADD.L D0,(A1,D1.L)
.HRELOCT5
DBF D3,.HRELOCT6
MOVE.L A2,A1 ;FREE THE MEM OF SIZE OF RELOCTABLE
MOVE.L (A4),D0
LSL.L #2,D0
ADDQ.L #7,D0
AND.L #$FFFFFFF8,D0
BSR.W FREEM
BRA.W .HRELOCT
.HSYMBOLT
MOVE.L D6,D1
MOVE.L A4,D2
MOVEQ.L #4,D3
BSR.W DOSLOAD ;GET NAMELENGTH
TST.L